package com.family.service.impl;

import com.family.mapper.NameMapper;
import com.family.model.Name;
import com.family.model.User;
import com.family.service.NameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("nameService")
public class NameServiceImpl /*extends SqlSessionDaoSupport */ implements NameService {
    private NameMapper nameMapper;

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setNameMapper(NameMapper nameMapper) {
        this.nameMapper = nameMapper;
    }

    public NameMapper getNameMapper() {
        return nameMapper;
    }

    @Override
    public Name addName(Name name) {
        Name nameModel = nameMapper.getNameByName(name.getName());
        if (nameModel == null) {
            int id = nameMapper.addName(name);
            name.setId(id);
            return name;
        } else {
            return nameModel;
        }
    }

    @Override
    public Name getNameById(int id) {
        return nameMapper.getNameById(id);
    }

    @Override
    public Name getNameByName(String name) {
        return nameMapper.getNameByName(name);
    }


}
